/**
 *
 */
package com.angel.annotation.finders;

import java.lang.annotation.Annotation;

import com.angel.annotation.interfaces.AnnotationObjectFinder;

/**
 *
 * @author William
 *
 */
public class AnnotationPackageFinder implements AnnotationObjectFinder{

	private static AnnotationObjectFinder instance;

	private AnnotationPackageFinder(){
		super();
	}

	public static synchronized AnnotationObjectFinder getInstance(){
		if(instance == null){
			instance = new AnnotationPackageFinder();
		}
		return instance;
	}

	public <T extends Annotation> Annotation findAnnotationAt(Object object, Class<T> annotationClass) {
		Package objectClassPackage = object.getClass().getPackage();
		return objectClassPackage.getAnnotation(annotationClass);
	}

	public <T extends Annotation> Object findTargetObjectFor(Object object, Class<T> annotationClass) {
		Annotation annotation = this.findAnnotationAt(object, annotationClass);
		if(annotation != null){
			return object.getClass().getPackage();
		}
		return null;
	}

}
